const redis = require("redis");
// redis配置
const client = redis.createClient('6379','ip',{auth_pass:'xxx'});

// 设置redis中的值
var setValue = (key,value)=>{
    return new Promise((resolve,reject)=>{
        client.set(key,value,(error,result)=>{
            if( error)  throw error;
            resolve(result) 
        }); 
    })
   
}

// 判断redis中是否存在key 
var exists = (key)=>{
    return new Promise((resolve,reject)=>{
        client.exists(key,(error,status)=>{
            if(error)  throw error;
            // 存在
            if(status == 1 ) resolve(true);
            else resolve(false);
        }) 
    }) 
}

// 从redis中获取数据
var getValue = (key)=>{
    return new Promise((resolve,reject)=>{
        client.get(key,(error,data)=>{
            if(error) throw error
            resolve(data);  
        });
    }) 
}


// 导出
exports.setValue_ = setValue;
exports.getValue_ = getValue;
exports.exists_  = exists;